home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / share / tod / setup.exe / hgrcos.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-10  |  884 b   |  39 lines

  1. #include <allegro.h>
  2. #include "hgrcos.inc"
  3.  
  4. /* Allegro has a 512-entry cosine table.  I need much more.
  5.  * I am using a 4096-entry cosine table.
  6.  */
  7.  
  8. fixed hgrcos(fixed theta)
  9. {
  10.   /* rescale theta to 0-4095 */
  11.   theta = ((theta + 0x800) & 0xfff000) >> 12;
  12.  
  13.   /* Switch on the quadrant. */
  14.   switch(theta >> 10)
  15.   {
  16.     case 0: /* first quadrant, return raw value */
  17.       return hirescostable[theta];
  18.     case 1: /* second quadrant */
  19.       return -hirescostable[2048 - theta];
  20.     case 2: /* third quadrant */
  21.       return -hirescostable[theta - 2048];
  22.     case 3: /* fourth quadrant */
  23.       return hirescostable[4096 - theta];
  24.     default:/* should never get here */
  25.       return 0;
  26.   }
  27. }
  28.  
  29.  
  30. fixed hgrsin(fixed theta)
  31. {
  32.   return hgrcos(theta + 0xc00000);
  33. }
  34.  
  35. fixed hgrtan(fixed theta)
  36. {
  37.   return fdiv(hgrcos(theta + 0xc00000), hgrcos(theta));
  38. }
  39.